home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_351 / pdc / libsrc.lzh / LibSrc / Math / asin.c < prev    next >
C/C++ Source or Header  |  1990-04-07  |  3KB  |  113 lines

  1. /************************************************************************
  2.  *                                                                      *
  3.  *                              N O T I C E                             *
  4.  *                                                                      *
  5.  *                      Copyright Abandoned, 1987, Fred Fish            *
  6.  *                                                                      *
  7.  *      This previously copyrighted work has been placed into the       *
  8.  *      public domain by the author (Fred Fish) and may be freely used  *
  9.  *      for any purpose, private or commercial.  I would appreciate     *
  10.  *      it, as a courtesy, if this notice is left in all copies and     *
  11.  *      derivative works.  Thank you, and enjoy...                      *
  12.  *                                                                      *
  13.  *      The author makes no warranty of any kind with respect to this   *
  14.  *      product and explicitly disclaims any implied warranties of      *
  15.  *      merchantability or fitness for any particular purpose.          *
  16.  *                                                                      *
  17.  ************************************************************************
  18.  */
  19.  
  20. /*
  21.  *  FUNCTION
  22.  *
  23.  *      asin   double precision arc sine
  24.  *
  25.  *  KEY WORDS
  26.  *
  27.  *      asin
  28.  *      machine independent routines
  29.  *      trigonometric functions
  30.  *      math libraries
  31.  *
  32.  *  DESCRIPTION
  33.  *
  34.  *      Returns double precision arc sine of double precision
  35.  *      floating point argument.
  36.  *
  37.  *      If argument is less than -1.0 or greater than +1.0, calls
  38.  *      matherr with a DOMAIN error.  If matherr does not handle
  39.  *      the error then prints error message and returns 0.
  40.  *
  41.  *  USAGE
  42.  *
  43.  *      double asin (x)
  44.  *      double x;
  45.  *
  46.  *  REFERENCES
  47.  *
  48.  *      Fortran IV-plus user's guide, Digital Equipment Corp. pp B-2.
  49.  *
  50.  *  RESTRICTIONS
  51.  *
  52.  *      For precision information refer to documentation of the floating
  53.  *      point library primatives called.
  54.  *      
  55.  *  PROGRAMMER
  56.  *
  57.  *      Fred Fish
  58.  *
  59.  *  INTERNALS
  60.  *
  61.  *      Computes arcsine(x) from:
  62.  *
  63.  *              (1)     If x < -1.0 or x > +1.0 then
  64.  *                      call matherr and return 0.0 by default.
  65.  *
  66.  *              (2)     If x = 0.0 then asin(x) = 0.0
  67.  *
  68.  *              (3)     If x = 1.0 then asin(x) = PI/2.
  69.  *
  70.  *              (4)     If x = -1.0 then asin(x) = -PI/2
  71.  *
  72.  *              (5)     If -1.0 < x < 1.0 then
  73.  *                      asin(x) = atan(y)
  74.  *                      y = x / sqrt[1-(x**2)]
  75.  *
  76.  */
  77.  
  78. #include <stdio.h>
  79. #include "pml.h"
  80.  
  81. static char funcname[] = "asin";
  82.  
  83. double asin (x)
  84. double x;
  85. {
  86.     extern double atan ();
  87.     extern double sqrt ();
  88.     struct exception xcpt;
  89.  
  90.     DBUG_ENTER (funcname);
  91.     DBUG_3 ("asinin", "arg %le", x);
  92.     if ( x > 1.0 || x < -1.0) {
  93.         xcpt.type = DOMAIN;
  94.         xcpt.name = funcname;
  95.         xcpt.arg1 = x;
  96.         if (!matherr (&xcpt)) {
  97.             fprintf (stderr, "%s: DOMAIN error\n", funcname);
  98.             errno = EDOM;
  99.             xcpt.retval = 0.0;
  100.         }
  101.     } else if (x == 0.0) {
  102.         xcpt.retval = 0.0;
  103.     } else if (x == 1.0) {
  104.         xcpt.retval = HALFPI;
  105.     } else if (x == -1.0) {
  106.         xcpt.retval = -HALFPI;
  107.     } else {
  108.         xcpt.retval = atan ( x / sqrt (1.0 - (x * x)) );
  109.     }
  110.     DBUG_3 ("asinout", "result %le", xcpt.retval);
  111.     DBUG_RETURN (xcpt.retval);
  112. }
  113.